//
//  MHBaseButton.m
//  GoftApp
//
//  Created by admin on 15/8/26.
//  Copyright (c) 2015年 mohe. All rights reserved.
//

#import "MHBaseButton.h"

@implementation MHBaseButton
{
    UIColor *_normalColor;
    UIColor *_hightColor;
    
    UIColor *_selectedColor;
}

- (void)setSelectedColor:(UIColor *)color normalColor:(UIColor *)normalColor;
{
    _selectedColor = color;
    _normalColor = normalColor;
    [self setBackgroundColor:normalColor];
}
- (void)setNormalColor:(UIColor *)normalColor hightColor:(UIColor *)hightColor
{
    _normalColor = normalColor;
    _hightColor = hightColor;
    [self addTarget:self action:@selector(buttonBackGroundHighlighted:) forControlEvents:UIControlEventTouchDown];
    [self addTarget:self action:@selector(buttonBackGroundNormal:) forControlEvents:UIControlEventTouchUpInside];
    [self addTarget:self action:@selector(buttonBackTouchCancel:) forControlEvents:UIControlEventTouchCancel];
    [self setBackgroundColor:normalColor];
}
- (void)buttonBackTouchCancel:(UIButton *)sender
{
    sender.backgroundColor = _normalColor;
}
- (void)buttonBackGroundNormal:(UIButton *)sender
{
    sender.backgroundColor = _normalColor;
}
- (void)setEnabled:(BOOL)enabled
{
    [super setEnabled:enabled];
    if(enabled){
        [self setBackgroundColor:_normalColor];
    }else{
        [self setBackgroundColor:[_normalColor colorWithAlphaComponent:0.5]];
    }
}

- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    if(selected && _selectedColor){
        [self setBackgroundColor:_selectedColor];
    }else if(_normalColor){
        [self setBackgroundColor:_normalColor];
    }
    
}
//  button高亮状态下的背景色
- (void)buttonBackGroundHighlighted:(UIButton *)sender
{
    sender.backgroundColor = _hightColor;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
